//package com.pengzy.core.cloud_security;
//
//import com.alibaba.fastjson.JSONObject;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.pengzy.comment.web.result.JsonResult;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.core.io.buffer.DataBuffer;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.server.WebFilterExchange;
//import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler;
//import org.springframework.stereotype.Component;
//import reactor.core.publisher.Mono;
//
//import java.util.HashMap;
//
///**
// * 认证失败类
// * @author xiaozhi 2023/7/17
// */
//
//@Slf4j
//@Component
//public class AuthenticationFaillHandler  implements ServerAuthenticationFailureHandler {
//
//    @SneakyThrows
//    @Override
//    public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, AuthenticationException e) {
//        ServerHttpResponse response = webFilterExchange.getExchange().getResponse();
//        response.setStatusCode(HttpStatus.FORBIDDEN);
//        response.getHeaders().add("Content-Type", "application/json; charset=UTF-8");
// //       HashMap<String, String> map = new HashMap<>();
////        map.put("code", "000400");
////        map.put("message", e.getMessage());
//        log.error("access forbidden path={}", webFilterExchange.getExchange().getRequest().getPath());
//        ObjectMapper objectMapper = new ObjectMapper();
//        DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONBytes(JsonResult.error(e.getMessage())));
//        return response.writeWith(Mono.just(dataBuffer));
//    }
//
//}
